﻿@namespace BlazorFluentUI.Lists
@inherits FluentUIComponentBase
@typeparam TItem

<div role="columnheader"
     aria-sort=@(Column!.IsSorted ? (Column.IsSortedDescending ? "descending" : "ascending"): "none")
     aria-colindex=@ColumnIndex
     class=@($"ms-DetailsColumn{(Column.ColumnActionsMode != ColumnActionsMode.Disabled ? " is-actionable" : "")}{(string.IsNullOrEmpty(Column.Name) ? " is-empty" : "")}{(Column.IsPadded ? " is-padded" : "")}{(Column.IsIconOnly ? " is-iconOnly" : "")}")
     data-is-draggable=@IsDraggable
     draggable=@IsDraggable
     style=@($"width:{(Column.CalculatedWidth + DetailsRow<TItem>.CELL_LEFT_PADDING + DetailsRow<TItem>.CELL_RIGHT_PADDING + (Column.IsPadded ? DetailsRow<TItem>.CELL_EXTRA_RIGHT_PADDING : 0))}px;")>
    @if (IsDraggable)
    {
        @if (UseFastIcons)
        {
            <FontIcon IconName="GripperBarVertical"
                         ClassName="ms-DetailsColumn-gripperBar" />
        }
        else
        {
            <Icon IconName="GripperBarVertical"
                     ClassName="ms-DetailsColumn-gripperBar" />
        }
    }
    @if (ColumnHeaderTooltipTemplate != null)
    {
        @ColumnHeaderTooltipTemplate
    }
    else
    {
        <span class="ms-DetailsColumn-cellTooltip">
            <span id=@($"{ParentId}-{Column.Key}")
                  aria-label=@(Column.IsIconOnly ? Column.Name : null)
                  aria-labelledby=@(Column.IsIconOnly ? null : $"{ParentId}-{Column.Key}-name")
                  class="ms-DetailsColumn-cellTitle"
                  data-is-focusable=@(Column.ColumnActionsMode != ColumnActionsMode.Disabled)
                  role=@(Column.ColumnActionsMode != ColumnActionsMode.Disabled &&
                             (Column.OnColumnClick!= null || OnColumnClick.HasDelegate)
                             ? "button" : null)
                  aria-describedby=@(ColumnHeaderTooltipTemplate != null && HasAccessibleLabel() ? $"{ParentId}-{Column.Key}" : null)
                  @oncontextmenu=@(()=> OnColumnContextMenu.InvokeAsync(Column))
                  @onclick=@HandleColumnClick
                  aria-haspopup=@(Column.ColumnActionsMode == ColumnActionsMode.HasDropdown)
                  aria-expanded=@(Column.ColumnActionsMode == ColumnActionsMode.HasDropdown ? Column.IsMenuOpen : false)>
                <span id=@($"{ParentId}-{Column.Key}-name")
                      class="ms-DetailsColumn-cellName">
                    @if (!string.IsNullOrEmpty(Column.IconName) || !string.IsNullOrEmpty(Column.IconClassName))
                    {
                        @if (UseFastIcons)
                        {
                            <FontIcon IconName=@Column.IconName
                                         ClassName=@Column.IconClassName />
                        }
                        else
                        {
                            <Icon IconName=@Column.IconName
                                     ClassName=@Column.IconClassName />
                        }
                    }
                    @if (!string.IsNullOrEmpty(Column.IconSrc))
                    {

                        <Icon IconSrc=@Column.IconSrc
                                 ClassName=@Column.IconClassName />

                    }
                    @if (Column.IsIconOnly)
                    {
                        <span class="ms-DetailsColumn-accessibleLabel">@Column.Name</span>
                    }
                    else
                    {
                        @Column.Name
                    }
                </span>
                @if (Column.IsFiltered)
                {
                    @if (UseFastIcons)
                    {
                        <FontIcon IconName="Filter"
                                     ClassName="ms-DetailsColumn-nearIcon" />
                    }
                    else
                    {
                        <Icon IconName="Filter"
                                 ClassName="ms-DetailsColumn-nearIcon" />
                    }
                }
                @if (Column.IsSorted)
                {
                    @if (UseFastIcons)
                    {
                        <FontIcon IconName=@(Column.IsSortedDescending ? "SortDown" : "SortUp")
                                     ClassName="ms-DetailsColumn-sortIcon" />
                    }
                    else
                    {
                        <Icon IconName=@(Column.IsSortedDescending ? "SortDown" : "SortUp")
                                 ClassName="ms-DetailsColumn-sortIcon" />
                    }
                }
                @if (Column.IsGrouped)
                {
                    @if (UseFastIcons)
                    {
                        <FontIcon IconName="GroupedDescending"
                                     ClassName="ms-DetailsColumn-nearIcon" />
                    }
                    else
                    {
                        <Icon IconName="GroupedDescending"
                                 ClassName="ms-DetailsColumn-nearIcon" />
                    }
                }
                @if (Column.ColumnActionsMode == ColumnActionsMode.HasDropdown && !Column.IsIconOnly)
                {
                    @if (UseFastIcons)
                    {
                        <FontIcon IconName="ChevronDown"
                                     AriaHidden="true"
                                     ClassName="ms-DetailsColumn-filterChevron" />
                    }
                    else
                    {
                        <Icon IconName="ChevronDown"
                                 AriaHidden="true"
                                 ClassName="ms-DetailsColumn-filterChevron" />
                    }
                }
            </span>
        </span>
    }
</div>
@*@if (ColumnHeaderTooltipTemplate == null)
    {
        @if (HasAccessibleLabel())
        {
            <Label id=@($"{ParentId}-{Column.Key}-tooltip")
                   class="ms-DetailsHeader-accessibleLabel">
                @Column.AriaLabel
                @(Column.IsFiltered ? Column.FilterAriaLabel : null)
                @(Column.IsSorted ? (Column.IsSortedDescending ? Column.SortedDescendingAriaLabel : Column.SortedAscendingAriaLabel) : null)
                @(Column.IsGrouped ? Column.FilterAriaLabel : null)
            </Label>
        }
    }*@